from LinkStack import LinkStack

while True:
    input_str = input('dc:')
    stack = LinkStack()
    char_list = input_str.split(' ')
    for c in char_list:
        # 不是操作符，则入栈
        # if '+-p'.count(c.strip()) < 1:
        if c.strip() not in ['+', '-', 'p']:
            stack.push(int(c.strip()))
        else:
            if '+' == c.strip():
                top1 = stack.pop()
                top2 = stack.pop()
                result = top2 + top1
                # 将操作结果入栈
                stack.push(result)
            elif '-' == c.strip():
                top1 = stack.pop()
                top2 = stack.pop()
                result = top2 - top1
                # 将操作结果入栈
                stack.push(result)
            else:
                print(stack.pop())
                break
